/**
 * 
 */
package siac.com.util;

import javax.el.ELContext;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author dfancone
 *
 */
public class HttpJSFUtil {
       
     public static FacesContext getFacesContext(){  
         return FacesContext.getCurrentInstance();  
     }
     
     public static Application getApplication(){  
         return HttpJSFUtil.getFacesContext().getApplication(); 
     }   
     
     //public static ELResolver getELResolver(){  
       //  return HttpJSFUtil.getApplication().getELResolver(); 
    // }   
     
     public static ELContext getELContext(){  
         return HttpJSFUtil.getFacesContext().getELContext(); 
     }   
     
     public static ExternalContext getExternalContext(){  
         return HttpJSFUtil.getFacesContext().getExternalContext(); 
     }   
     
     public static ServletContext getServletContext(){  
         return (ServletContext)HttpJSFUtil.getExternalContext().getContext(); 
     }   
       
     public static HttpSession getSession(boolean status){  
         return (HttpSession)HttpJSFUtil.getExternalContext().getSession(status);  
     } 
       
     public static HttpServletRequest getRequest(){  
         return (HttpServletRequest)HttpJSFUtil.getExternalContext().getRequest();  
     }  
    
     public static HttpServletResponse getResponse(){  
         return(HttpServletResponse)HttpJSFUtil.getExternalContext().getResponse();  
     }   
    
     public static String getContextPath(){  
         return HttpJSFUtil.getRequest().getContextPath();  
     } 
     /*
     public static Object getManagedBean(FacesContext fc, String name){  
         return fc.getApplication().createValueBinding(name).getValue(fc);  
     }
       
     public static Object getManagedBean2(String name){  
         return FacesContext.getCurrentInstance().getApplication().createValueBinding(name).getValue(FacesContext.getCurrentInstance());          
     }
     
     public static Object getManagedBean(String nomeNoXML) {  
         return HttpJSFUtil.getELResolver().getValue(HttpJSFUtil.getELContext(), null, nomeNoXML);        
     } 
     */
	
	public static String getRealPath(String filename){
		return HttpJSFUtil.getServletContext().getRealPath("/" + filename);
	}
            
}  